package com.aegean.MonitorExamSYS.tool.action;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.aegean.MonitorExamSYS.tool.business.ToolBusiness;
import com.aegean.MonitorExaxSYS.model.ExamInfo;
import com.aegean.MonitorExaxSYS.model.ExamineeValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("ShowExamListForPublic")
@Scope("prototype")
public class ShowExamListForPublic extends ActionSupport implements
		ServletRequestAware {
	@Resource
	ToolBusiness business;
	private String userApp_BigComob;
	private String userApp_SmallComob;
	private HttpSession session;
	private HttpServletRequest request;

	public String getUserApp_BigComob() {
		return userApp_BigComob;
	}

	public void setUserApp_BigComob(String userApp_BigComob) {
		this.userApp_BigComob = userApp_BigComob;
	}

	public String getUserApp_SmallComob() {
		return userApp_SmallComob;
	}

	public void setUserApp_SmallComob(String userApp_SmallComob) {
		this.userApp_SmallComob = userApp_SmallComob;
	}

	private int examName_State;

	public int getExamName_State() {
		return examName_State;
	}

	public void setExamName_State(int examName_State) {
		this.examName_State = examName_State;
	}

	private int exam_status;// 查询的考试类型
	private int limit;
	private int start;
	private int pageNow;// 当前页
	private int totalRows;// 总条例个数
	private int pageCount;// 页数
	private int status;// 查询的种类
	private String exam_Name;// 关键字
	private String exam_Year;
	private String key_Name;
	private int small_Id;
	private Date startTime;
	private Date endTime;
	List<ExamInfo> exams;

	public String getExam_Year() {
		return exam_Year;
	}

	public void setExam_Year(String exam_Year) {
		this.exam_Year = exam_Year;
	}

	public int getSmall_Id() {
		return small_Id;
	}

	public void setSmall_Id(int small_Id) {
		this.small_Id = small_Id;
	}

	public int getExam_status() {
		return exam_status;
	}

	public void setExam_status(int exam_status) {
		this.exam_status = exam_status;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getPageNow() {
		return pageNow;
	}

	public void setPageNow(int pageNow) {
		this.pageNow = pageNow;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getExam_Name() {
		return exam_Name;
	}

	public void setExam_Name(String exam_Name) {
		this.exam_Name = exam_Name;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public List<ExamInfo> getExams() {
		return exams;
	}

	public void setExams(List<ExamInfo> exams) {
		this.exams = exams;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return SUCCESS;
	}

	public String search() throws Exception {
		// TODO Auto-generated method stub
		if (examName_State == 0) {
			session.setAttribute("examNameForSearch", exam_Name);
		} else {
			exam_Name = (String) session.getAttribute("examNameForSearch");
		}
		key_Name = "";
		if (exam_Year != null && !exam_Year.trim().equals("")) {
			key_Name = "%" + exam_Year + "%";
		}
		if (exam_Name != null && !exam_Name.trim().equals("")) {
			if (key_Name.endsWith("%")) {
				key_Name += exam_Name + "%";
			} else {
				key_Name = "%" + exam_Name + "%";
			}
		}
		limit = 15;
		totalRows = business.countExamList(key_Name, small_Id, exam_status,
				start, limit, exam_Name, startTime, endTime, 2);
		if ((totalRows % limit) == 0) {
			pageCount = totalRows / limit;
		} else {
			pageCount = totalRows / limit + 1;
		}
		if (pageNow > pageCount) {
			pageNow = pageCount;
		} else if (pageNow < 1) {
			pageNow = 1;
		}
		start = (pageNow - 1) * limit;
		exams = business.showExamList(key_Name, small_Id, exam_status, start,
				limit, exam_Name, startTime, endTime, 2);
		return SUCCESS;
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		this.session = request.getSession();

	}

}
